const { DataTypes } = require('sequelize');
// const sequelize = require('@/db/seq');
const sequelize = require("@/db/seq");

const Moment = sequelize.define('moment', {
  id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
  user_id: { type: DataTypes.INTEGER, allowNull: false, comment: '用户id' },
  content: { type: DataTypes.TEXT, allowNull: false, comment: '说说内容' },
  images: { type: DataTypes.JSON, allowNull: true, comment: '图片数组' },
  like_count: { type: DataTypes.INTEGER, defaultValue: 0, comment: '点赞数' },
  comment_count: { type: DataTypes.INTEGER, defaultValue: 0, comment: '评论数' },
}, { freezeTableName: true });
// Moment.sync({ alter: true })

Moment.associate = (models) => {
  Moment.belongsTo(models.blog_user, { foreignKey: 'user_id', as: 'author' });
  Moment.hasMany(models.moment_comment, { foreignKey: 'moment_id', as: 'comments' });
  Moment.hasMany(models.moment_like, { foreignKey: 'moment_id', as: 'likes' });
};

module.exports = Moment;